cmake_minimum_required(VERSION 2.6)
project(DRLCODE C CXX Fortran)

# set path right
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")

# find LAPACK
find_package(LAPACK REQUIRED)  # LAPACK finds BLAS as a dependency

# Set the directory for looking for local installations.
set(Local_ROOT "$ENV{HOME}/local")

# include Armadillo.
include_directories(${Local_ROOT}/armadillo/include)
link_directories(${Local_ROOT}/armadillo/lib)

# include GSL.
include_directories(${Local_ROOT}/gsl/include)

# include boost.
find_package(Boost COMPONENTS program_options mpi serialization system thread unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Set the MPI compiler.
set(MPI_COMPILER /usr/bin/mpicxx)

# find MPI
find_package(MPI)

if(MPI_FOUND)
  include_directories(${MPI_INCLUDE_PATH})
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_LINK_FLAGS}")
endif()

# Add additional complie flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Wall")
include_directories(${MPI_INCLUDE_DIR})
include_directories(${Local_ROOT}/hdf5/include)
link_directories(${Local_ROOT}/hdf5/lib)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)

## recurse
include_directories(${CMAKE_SOURCE_DIR})
set(CORE_LIBRARIES ${MPI_LIBRARIES})
add_subdirectory(core)
add_subdirectory(mlpack)
